package com.richinfo.demo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.richinfo.demo.entity.Area;
import com.richinfo.demo.service.AreaService;

/**
* Created by WangXJ
* 2018-05-07 14:37
*/
@RestController
@RequestMapping("/superadmin")
public class AreaController {

	@Autowired
	private AreaService areaService;
	
	/**
	 * 列出所有区域
	 * @return
	 */
	@GetMapping("/listareas")
	public Map<String, Object> listArea(){
		Map<String, Object> modelMap = new HashMap<String,Object>();
		List<Area> areas = areaService.getAllAreas();
		modelMap.put("areaList", areas);
		return modelMap;
	}
	
	/**
	 * 通过区域Id查询指定区域
	 * @param areaId
	 * @return
	 */
	@GetMapping("/getareabyid/{areaId}")
	public Map<String, Object> getAreaById(@PathVariable("areaId") Integer areaId){
		Map<String, Object> modelMap = new HashMap<String,Object>();
		Area area = areaService.getAreaById(areaId);
		modelMap.put("area", area);
		return modelMap;
	}
	
	/**
	 * 新增区域
	 * @param area
	 * @return
	 */
	@PostMapping("/addarea")
	public Map<String, Object> addArea(@RequestBody Area area){
		Map<String, Object> modelMap = new HashMap<String,Object>(); 
		boolean result = areaService.addArea(area);
		modelMap.put("result", result);
		return modelMap;
	}
	
	/**
	 * 修改区域信息
	 * @param area
	 * @return
	 */
	@PutMapping("/modifyarea")
	public Map<String, Object> modifyArea(@RequestBody Area area){
		Map<String, Object> modelMap = new HashMap<String,Object>();
		boolean result = areaService.modifyArea(area);
		modelMap.put("result", result);
		return modelMap;
	}
	
	/**
	 * 通过areaId删除区域
	 * @param areaId
	 * @return
	 */
	@DeleteMapping("/removearea/{areaId}")
	public Map<String, Object> removeArea(@PathVariable("areaId") Integer areaId){
		Map<String, Object> modelMap = new HashMap<String,Object>();
		boolean result = areaService.deleteArea(areaId);
		modelMap.put("result", result);
		return modelMap;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
